<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
	img {
		height:50px;
		width:50px;
	}
</style>
<script type="text/javascript">
	$(function() {
		$('#comments_grid_toolbar').toolbar({buttons:[
           	{name:'add_tag',iconCls:'icon-add',text:'添加话题评论'},
      	],handler:handler});
		$('#topic_grid').datagrid({
	    	url:'/group/topic/page',
    		pagination:true,
    		pageSize:20,
    		singleSelect:true,
    		rownumbers:false,
    		striped:true,
    		fit:true,
    		fitColumns:true,
    		toorbar:'#toolbar_articleTable',
    		columns:[[
    			{field:'id',title:'编号'},
    			{field:'articleTitle',title:'文章标题'},
        		{field:'nickname',title:'作者'},
        		{field:'articleType',title:'类型',formatter:function(v,r,i){
        			var type ="";
        			if(r.articleType == "1"){type ="文章"}else if(r.articleType == "3"){type ="音频"}else if(r.articleType == "5"){type="视频"}else if(r.articleType == "7"){type="话题pk"}
        			return type;
        		}},
        		{field:'countView',title:'浏览量'},
        		{field:'countPraise',title:'点赞量'},
        		{field:'countShare',title:'分享量'},
        		{field:'countCollect',title:'收藏量'},
        		{field:'createdDt',title:'创建时间'},
    		]],
    		view: detailview,
    		detailFormatter: function(rowIndex, rowData){
    	    	var details;
    	    	if(rowData.articleType == '1'){
    	    		details = '<table><tr>' +
	                '<td rowspan=2 style="border:0,height:50px;">'+rowData.articleTitle+'</td>' +
	                '</tr></table>';
    	    	}else if(rowData.articleType == '2'){
    	    		details = '<table><tr>' +
	                '<td rowspan=2 style="border:0,height:50px;">'+rowData.articleContent+'</td>' +
	                '</tr></table>';
    	    	}
    	        return details;
    	    },
    	    onSelect:loadTags
		 });
	    $('#comments_grid').datagrid({
	    	pagination:true,
			singleSelect:true,
			fitColumns:true,
			fit:true,
			method:'post',
			columns:[[
				{field:'ck',checkbox:true},
				{field:'id',title:'评论编号'},
				{field:'pid',title:'父评论id'},
				{field:'articleId',title:'话题id'},
				{field:'commentUserId',title:'评论人'},
				{field:'commentReplyUserId',title:'评论回复人'},
				{field:'commentContent',title:'评论内容'},
				{field:'countPraise',title:'点赞数量'},
				{field:'enabled',title:'删除标记',formatter:function(v,r,i){
					var show = '删除';
					if(r.enabled){
						show='正常';	
					}
					return show;
				}},
				
				{field:'action',title:'操作',formatter:function(v,r,i){
					var action = '';
					if(r.enabled){
						action = '<a href="#" onclick="updateEnblse('+r.id+');">禁用</a>'
					}
					action = action + '&nbsp;&nbsp;<a href="#" onclick="toEdit('+i+');">回复</a>';
					return action;
				}}
			]],
			
		 });
	     
	    function loadTags(index,row){
	    	var param = {};
	    	param.articleId = row.id;
	    	$('#comments_grid').datagrid({ 
	    		queryParams: param,
	    		url:"page"
	    	});   
	    }
	    
		 //过滤条件参数
		function getItem(){
			var userName = $.trim($("#search_user").textbox("getValue"));
			var articleTitle = $.trim($("#search_articleTitle").textbox("getValue"));
			var articleType = $.trim($("#search_articleType").combobox("getValue"));
			var enabled = $.trim($("#search_enabled").combobox("getValue"));
			var searchItem = {};
			if(userName.length>0){
				searchItem.userName=userName;
			}
			if(articleTitle.length>0){
				searchItem.articleTitle=articleTitle;
			}
			if(articleType.length>0){
				searchItem.articleType=articleType;
			}
			if(enabled.length>0){
				searchItem.enabled=enabled;
			}
			return searchItem;
		}
		function handler() {
			switch(this.name) {
				case 'add_tag': toAdd();break;
				case 'save_category': saveCategory();break;
			}
		}
		function toAdd() {
			var row = $('#topic_grid').datagrid("getSelected");
			if(row != null && row != ""){
				var articleId = row.id;
				show({code:'tag_info_add',title:'添加标签信息',iconCls:'icon-add',uri:'add?articleId='+row.id,
						width:500,height:390,
					options : {
						success : function(data) { 
							$('#comments_grid').datagrid("reload");
						}
					}
				});
			}else{
				top.$ok('请选择话题');
			}
		}
	
	$("#a_searchTag").click(function(){
		reloadDate();
	});
	$("#a_clearn").click(function(){
		resetData();
	});
		
		function reloadDate(){
			var item = getItem();
			$('#topic_grid').datagrid({ queryParams: item});   //点击搜索
		}
		function resetData(){
			$("#search_user").textbox("setValue","");
			$("#search_articleTitle").textbox("setValue","");
			$("#search_articleType").combobox("setValue","");
			$("#search_enabled").combobox("setValue","");
			reloadDate();
		}
		
	});
	function toEdit(index) {
		$('#comments_grid').datagrid("selectRow",index);
		var row = $('#comments_grid').datagrid("getSelected");
		if(row != null && row != ""){
			var articleId = row.id;
			show({code:'tag_info_add',title:'添加标签信息',iconCls:'icon-add',uri:'edit?id='+row.id,width:500,height:390,
				options : {
					success : function(data) { 
						$('#comments_grid').datagrid("reload");
					}
				}
			});
		}else{
			top.$ok('请选择话题');
		}
	}
	//查看详细
	function detail(id){
		console.log("详细");
	}
	//移除标签
	function updateEnblse(id){
		 var parms = {};
		 parms.id = id;
		 parms.enable ="false";
		 $.post('updateEnable',parms,function(r){
				if(r.code>0){
					top.$prompt('禁用成功');
					$('#comments_grid').datagrid('reload'); 
				};
			},'json');
	 }
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false">
			<fieldset>
	    		<legend>过滤条件</legend>
	    		<table style="width:100%">
	    			<tr>
	    				<td>话题标题:<input id="search_articleTitle" class="easyui-textbox" data-options="prompt:'请输入话题名称'" ></td>
	    				<td>话题作者:<input id="search_user" class="easyui-textbox" data-options="prompt:'请输入作者'" ></td>
	    				<td>
	    					话题类型:
	    					<select id="search_articleType" class="easyui-combobox" data-options="width:60,panelHeight:100">
	    						<option></option>
	    						<option value="1">短文</option>
	    						<option value="2">长文</option>
	    					</select>
	    				</td>
	    				<td>
	    					是否可用:
	    					<select id="search_enabled" class="easyui-combobox" name="enabled" data-options="width:50,panelHeight:60">
	    						<option> </option>
	    						<option value="1">是</option>
	    						<option value="0">否</option>
	    					</select>
	    				</td>
	    				<td><a id="a_searchTag" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
	    				<td>
	    					<a id="a_clearn" class="easyui-linkbutton" iconCls="icon-undo">清除</a>
	    				</td>
	    			</tr>
	    		</table>
	  		</fieldset>
		</div>
		<div data-options="region:'east',split:true,collapsible:false" title="话题评论信息" style="width:50%;padding-bottom: 33px">
			<div id="comments_grid_toolbar" class="toolbar" ></div>
			<table id="comments_grid" class="easyui-datagrid"></table>
		</div>
  		<div data-options="region:'center',border:true" title="话题信息" style="width:50%;padding-bottom: 33px">
  			<table id="topic_grid"></table>
		</div>
	</div>
</body>
</html>